package br.com.gkarian.mydesk.dao.financeiro;

import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

import br.com.caelum.vraptor.ioc.Component;
import br.com.gkarian.mydesk.dao.financeiro.interfaces.TipoTransacaoDAO;
import br.com.gkarian.mydesk.model.financeiro.TipoTransacao;

@Component
public class TipoTransacaoDAOImpl implements TipoTransacaoDAO {

	private static final Logger LOG = Logger.getLogger(TipoTransacaoDAOImpl.class);
	
	private SessionFactory sf;
	
	public TipoTransacaoDAOImpl(SessionFactory sf) {
		this.sf = sf;
	}
	
	private Session getSession() {
		return this.sf.getCurrentSession();
	}

	@Override
	public TipoTransacao salvar(TipoTransacao tipoTransacao) throws Exception {
		return (TipoTransacao) getSession().merge(tipoTransacao);
	}

	@Override
	public void atualizar(TipoTransacao tipoTransacao) throws Exception {
		getSession().update(tipoTransacao);
	}

	@Override
	public void remover(TipoTransacao tipoTransacao) throws Exception {
		getSession().delete(tipoTransacao);
	}
	
	@Override
	public TipoTransacao carregar(Integer id) throws Exception {
		return (TipoTransacao) getSession().load(TipoTransacao.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<TipoTransacao> listarTudo() throws Exception {
	    return getSession().createCriteria(TipoTransacao.class).list();
    }
	



}
